#ifndef _NFC_HAL_CONFIG_H_
#define _NFC_HAL_CONFIG_H_

#include "nfc_hal_transfer.h"
#include "nfc_hal_dpo.h"
#include "bit_define.h"
#include "reader_reg.h"

#define COMPAT_SETTING_FLAG         0xFF
#define HAL_CONFIG_END_FLAG         0xFE

typedef struct
{
    uint8_t page;
    uint8_t addr;
    uint8_t value;
} hal_nfc_regval_t;

typedef enum
{
    HAL_TECH_TYPE_A,
    HAL_TECH_TYPE_B,
    HAL_TECH_TYPE_F,
    HAL_TECH_TYPE_V,
} hal_nfc_tech_type_t;

void hal_nfc_bit_set(uint8_t page, uint8_t addr, uint8_t value, uint8_t page_sel);
void hal_nfc_bit_clear(uint8_t page, uint8_t addr, uint8_t value, uint8_t page_sel);
uint8_t hal_nfc_bit_check(uint8_t page, uint8_t addr, uint8_t check_bit, uint8_t page_sel);
int hal_nfc_set_register(uint8_t page, uint8_t addr, uint8_t value, uint8_t page_sel);
static inline void hal_nfc_test_pin_on(void)
{
    hal_nfc_write_register(REG_TESTPINEN, 0x9E);
    hal_nfc_write_register(REG_TESTPINVALUE, 0x80);
}

static inline void hal_nfc_test_pin_off(void)
{
    hal_nfc_write_register(REG_TESTPINEN, 0x9E);
    hal_nfc_write_register(REG_TESTPINVALUE, 0x9E);
}

/* 读卡器复位 */
static inline void hal_nfc_pcd_reset(void)
{
    hal_nfc_write_register(REG_COMMAND, PCD_RESETPHASE);
}

/* 开启载波 */
static inline void hal_nfc_antenna_on(void)
{
    hal_nfc_set_register(0, 0x14, 0x3, 1);
}

/* 关闭载波 */
static inline void hal_nfc_antenna_off(void)
{
    hal_nfc_set_register(0, 0x14, 0, 1);
}

int hal_nfc_config(hal_nfc_regval_t *config, uint8_t size);
uint8_t hal_nfc_get_register(uint8_t page, uint8_t addr, uint8_t page_sel);

uint32_t htonl(uint32_t lval);
uint32_t ntohl(uint32_t lval);

void pcd_set_tmo(uint8_t fwi);
void pcd_set_rate(uint8_t rate, uint8_t type);
void pcd_delay_sfgi(uint8_t sfgi);

void pcd_set_tmo_FWT_n9(void);
void pcd_set_tmo_FWT_ACTVITION(void);
void pcd_set_tmo_FWT_ATQB(void);
#endif
